package com.mapper;

import com.entity.Supplier;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  供应商Mapper 接口
 * </p>
 *
 * @author aiou
 * @since 2025-06-09
 */
@Mapper
public interface SupplierMapper{

    /**
     * 根据供应商编码查询供应商
     * @param supplierCode
     * @return
     */
    Supplier selectAllByCode(String supplierCode);

    /**
     * 查询所有供应商
     * @return
     */
    List<Supplier> list();

    /**
     * 删除供应商
     * @param id
     * @return
     */
    @Delete("delete from supplier where supplier_id = #{id}")
    boolean deleteById(Integer id);

    /**
     * 供应商管理-保存
     * @param supplier
     * @return
     */
    @Insert("insert into supplier(supplier_code,supplier_name,address,country,province,city,contact,email,phone,tax_id,bank_name,bank_account,bank_chairman,remark) " +
             "values(#{supplierCode},#{supplierName},#{address},#{country},#{province},#{city},#{contact},#{email},#{phone},#{taxId},#{bankName},#{bankAccount},#{bankChairman},#{remark})")
    boolean save(Supplier supplier);

    /**
     * 供应商管理-修改
     * @param supplier
     * @return
     */
    @Update("update supplier set supplier_code = #{supplierCode},supplier_name = #{supplierName},address = #{address},country = #{country}," +
            "province = #{province},city = #{city},contact = #{contact},email = #{email},phone = #{phone},tax_id = #{taxId}," +
            "bank_name = #{bankName},bank_account = #{bankAccount}," +
            "bank_chairman = #{bankChairman} where supplier_id=#{supplierId}")
    boolean updateById(Supplier supplier);
}
